<?php

/*
 *
 * 数据库操作查询类
 * */
namespace app\admin\controller;
use app\admin\model\Admin as AdminModel;
use think\Controller;
use think\db\exception\DataNotFoundException;
use think\db\exception\ModelNotFoundException;
use think\exception\DbException;

class Admin extends Controller
{
    public function index(){
        //TODO 这个肯定没写完
        return "这是admin";
    }

    /*查询所有的admin用户*/
    public function selectAll(){
        $data = new AdminModel();
        try {
            $data = $data->selectOrFail();
        } catch (DataNotFoundException $e) {
        } catch (ModelNotFoundException $e) {
        } catch (DbException $e) {
        }
        return $data->toArray();
    }

    /*根据用户email登录*/
    public function selectPassword($name){
        try {
            $data = AdminModel::where("admin_name", $name)->findOrEmpty();
            /*一定要看文档！*/
            return $data->toArray();
//            return json($data);
        } catch (DataNotFoundException $e) {
        } catch (ModelNotFoundException $e) {
        } catch (DbException $e) {
        }
    }

}